package com.aceitunaproject.mapdisplay;


import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import com.aceitunaproject.mapdisplay.component.MapPane;
import com.aceitunaproject.mapdisplay.model.Thing;
import com.aceitunaproject.mapdisplay.model.map.tile.Tile;

/**
 * Instancia un JFrame con un JDesktopPane y dentro de este un JInternalFrame.
 * 
 * @author chuidiang
 * 
 */
public class MapPaneCheck {

	/** Instancia esta clase */
	public static void main(String[] args) {
		theFrame = new MapPaneCheck();
	}

	public MapPane dp;
	public static MapPaneCheck theFrame;
	JFrame v ;
	/**
	 * Crea el JFrame, el JDesktopPane, un JInternalFrame de muestra y lo
	 * visualiza.
	 */
	public MapPaneCheck() {

		// El JFrame con el JDesktopPane
		v = new JFrame("Map Pane Test");
		dp = new MapPane(getMap());
		v.getContentPane().add(dp);
		v.addKeyListener(new KeyListener() {

			public void keyPressed(KeyEvent arg0) {
				dp.setMapModel(getMap2());
////				v.remove(dp);
//				dp = new MapPane(getMap2());
//				dp.repaint();
//				dp.paintComponent(dp.getGraphics());
////				v.add(dp);
//				v.repaint();
			}

			public void keyReleased(KeyEvent arg0) {
				// TODO Auto-generated method stub

			}

			public void keyTyped(KeyEvent arg0) {
				// TODO Auto-generated method stub

			}

		});

		// Se visualiza todo.
		v.setSize(1000, 500);
		v.setVisible(true);
		v.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		try {
			// gui = new MapDrawerImpl(dp,getMap(), new Dimension(1000, 500));
			// dp.setGUI(gui);
			// gui.setFocus(0,0);
			// v.addMouseListener(new MouseListenerImpl(gui));
			// gui.setDisplayGrid(false);

			dp.repaint();
		} catch (Exception e) {

			e.printStackTrace();
		}

	}

	private Tile[][] getMap() {
		Tile[][] tile = new Tile[5][10];
		for (int i = 0; i < tile.length; i++) {
			for (int j = 0; j < tile[i].length; j++) {
				tile[i][j] = createTile(i, j, "grassland");

			}
			;

		}
		tile[2][2] = createTile(2, 2, "plains");
		tile[4][4] = createTile(4, 4, "marsh");
		// tile[2][6] = createTile(2, 6, "hills");
		// tile[2][7] = createTile(2, 7, "hills");
		// tile[2][8] = createTile(2, 8, "hills");
		tile[4][2] = createTile(4, 2, "ocean");
		Thing icoIco = new Thing("Horse");
		Thing ico = new Thing("Artillery");
		Thing ico2 = new Thing("veteranSoldier");
		Thing barquito = new Thing("merchantman");
		Thing montanita = new Thing("hills");
		tile[1][1].addThing(ico2);
		tile[1][1].addThing(ico);
		tile[3][3].addThing(icoIco);
		tile[4][2].addThing(barquito);
		tile[2][6].addThing(montanita);
		tile[2][7].addThing(montanita);
		// tile[2][2].addThingNoUpdate(new Unit(Acelga.getSpecification()
		// .getUnitType("model.unit.freeColonist")));

		return tile;
	}

	private Tile[][] getMap2() {
		Tile[][] tile = new Tile[5][10];
		for (int i = 0; i < tile.length; i++) {
			for (int j = 0; j < tile[i].length; j++) {
				tile[i][j] = createTile(i, j, "grassland");

			}
			;

		}
		tile[2][2] = createTile(2, 2, "plains");
		tile[4][4] = createTile(4, 4, "marsh");
		// tile[2][6] = createTile(2, 6, "hills");
		// tile[2][7] = createTile(2, 7, "hills");
		// tile[2][8] = createTile(2, 8, "hills");
		tile[4][2] = createTile(4, 2, "ocean");
		Thing icoIco = new Thing("veteranSoldier");
		Thing ico = new Thing("veteranSoldier");
		Thing ico2 = new Thing("veteranSoldier");
		Thing barquito = new Thing("merchantman");
		Thing montanita = new Thing("hills");
		tile[1][1].addThing(ico2);
		tile[1][1].addThing(ico);
		tile[3][3].addThing(icoIco);
		tile[4][2].addThing(barquito);
		tile[2][6].addThing(montanita);
		tile[2][7].addThing(montanita);
		// tile[2][2].addThingNoUpdate(new Unit(Acelga.getSpecification()
		// .getUnitType("model.unit.freeColonist")));

		return tile;
	}

	
	
	private Tile createTile(int x, int y, String name) {

		return new Tile(name, x, y);

	}

}
